package org.zfes.snowier.cloud.zbss.metting.router.service.tenant;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.zfes.snowier.common.file.FileResInfo;
import org.zfes.snowier.common.file.UeditorState;
import org.zfes.snowier.common.file.disk.UploadUitl;
import org.zfes.snowier.core.util.ZAlert;
import org.zfes.snowier.core.util.ZAssert;
import org.zfes.snowier.web.controller.BaseController;

@Controller("org.zfes.snowier.cloud.zbss.metting.router.service.pub.CmsUploadController")
@RequestMapping("/met/service/tenant/upload")
public class CmsUploadController extends BaseController{
	
	@RequestMapping(value="/uploadDoc", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object uploadProjecDoc(@RequestParam(name="file",required=false)MultipartFile file)  {
		ZAssert.notNull(file,"请选择文件");
		 try {
			 FileResInfo resInfo=  UploadUitl.tranferFile(file,"");
			 return ajaxQuery("fileUrl",resInfo.getFileUrl());
		 }catch (Exception e) {
			e.printStackTrace();
			ZAlert.Error("选择上传错误");
		}
		 
		return ajaxQuery("docPath", "");
	}

	
	@RequestMapping(value="/uploadUeditorCMsImg", method = { RequestMethod.POST,  RequestMethod.GET },produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object UploadUeditorImg(@RequestParam(name="upfile",required=false)MultipartFile file)  {
	
		 try {
			 ZAssert.notNull(file,"请选择文件");
			 FileResInfo resInfo =  UploadUitl.tranferFile(file,"");
			 return new UeditorState( "SUCCESS", resInfo.getFileUrl() ).setOriginal(resInfo.getFileOriginName()).setTitle("");
			 
		 }catch (Exception e) {
			e.printStackTrace();
			 return new UeditorState("上传失败").setTitle("上传失败：【"+e.getMessage()+"】");
		}
	}
	@RequestMapping(value="/uploadCaseImg", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object uploadCaseImg(@RequestParam(name="file",required=false)MultipartFile file)  {
		ZAssert.notNull(file,"请选择文件");
		 try {
			 FileResInfo resInfo=UploadUitl.tranferFile( file,  "casez"); 
			 return ajaxQuery("fileUrl",resInfo.getFileUrl());
		 }catch (Exception e) {
			e.printStackTrace();
			ZAlert.Error("选择上传错误");
		}
		 return ajaxQuery("fileUrl", "");
	}
	@RequestMapping(value="/uploadCmsImg", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object uploadImg(@RequestParam(name="file",required=false)MultipartFile file,Integer contentType)  {
		ZAssert.notNull(contentType, "类型参数不能为空");
		ZAssert.notNull(file,"请选择文件");
		 try {
			 FileResInfo resInfo=UploadUitl.tranferFile( file, getAssignFileName( contentType), "sitz", false); 
			 return ajaxQuery("fileUrl",resInfo.getFileUrl());
		 }catch (Exception e) {
			e.printStackTrace();
			ZAlert.Error("选择上传错误");
		}
		 return ajaxQuery("docPath", "");
	}
	
//	1	LOGO	{[w_283,h_35]，[要求背景透明的PNG]}	  
//	2	首页轮播图-1 (建议带有：让会议组织变得简单等宣传字符)	{[w_1920,h_620]，[要求JPG]}	  
//	3	首页轮播图-2 (建议带有宣传字符)	{[w_1920,h_620]，[要求JPG]}	  
//	4	扫描关注微信公众号	{[w_120,h_116]，[要求PNG]}	  
//	5	扫描浏览手机站	{[w_120,h_116]，[要求PNG]}	  
//	6	平台服务-1:平台服务部分左上角大图	{[w_801,h_280]，[要求JPG]}	  
//	7	平台服务-2:平台服务部分底部图1	{[w_400,h_280]，[要求JPG]}	  
//	8	平台服务-3:平台服务部分底部图2	{[w_400,h_280]，[要求JPG]}	  
//	9	首页底部会议资讯图	{[w_488,h_200]，[要求JPG]}
	//类型_Q_D#
	//1关于我们，2服务热线，3联系我们-公司邮箱，4联系我们-公司传真，5联系我们-公司地址，6联系我们-经纬度地址，7联系我们-咨询热线	8会议注册开通协议，9案例编辑，10问题指南--开通说明，11问题指南--常见问题，12资讯 #
	private String getAssignFileName(Integer contentType) {
		switch (contentType) {
		case 1:
			return "logo.png";
		case 2:
			return "slideshow1.jpg";
		case 3:
			return "slideshow2.jpg";
		case 4:
			return "weichat.png";
		case 5:
			return "wapsite.png";
		case 6:
			return "plant1.jpg";
		case 7:
			return "plant2.jpg";
		case 8:
			return "plant3.jpg";
		case 9:
			return "info_index.jpg";
		default:
			ZAlert.serviceLogicalError("类型参数错误");
		}
		return "";
	}
	

}
